"""
序列化器--外键关系
"""
from rest_framework import serializers
from employee.models import Employee, Salary


class EmpSerializer(serializers.ModelSerializer):
    class Meta:
        model = Employee
        fields = '__all__'


class SalarySerializer(serializers.ModelSerializer):
    class Meta:
        model = Salary
        fields = '__all__'


print('~' * 30)
print(EmpSerializer())
print(SalarySerializer())
print('~' * 30)

""" 结果
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
EmpSerializer():
    emp_no = IntegerField(label='工号', max_value=2147483647, min_value=-2147483648, validators=[<UniqueValidator(queryset=Employee.objects.all())>])
    birth_date = DateField(label='生日')
    first_name = CharField(label='名', max_length=14)
    last_name = CharField(label='姓', max_length=16)
    gender = ChoiceField(choices=[(1, '男'), (2, '女')], label='性别', validators=[<django.core.validators.MinValueValidator object>, <django.core.validators.MaxValueValidator object>])
    hire_date = DateField()
    email = EmailField(allow_blank=True, allow_null=True, max_length=254, required=False)
    content = CharField(allow_blank=True, allow_null=True, required=False, style={'base_template': 'textarea.html'})
    created = DateTimeField(read_only=True)
    updated = DateTimeField(read_only=True)
SalarySerializer():
    id = IntegerField(read_only=True)
    from_date = DateField()
    salary = IntegerField(label='工资', max_value=2147483647, min_value=-2147483648)
    to_date = DateField()
    emp_no = PrimaryKeyRelatedField(queryset=Employee.objects.all())
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"""

"""
SalarySerializer
	id是read_only，因为自增字段，入库时不用手动指定id
	emp_no是主键关联
"""
